﻿namespace CKFinder.Connector
{
    using CKFinder.Connector.CommandHandlers;
    using CKFinder.Settings;
    using System;
    using System.Text.RegularExpressions;
    using System.Web.UI;

    public class Connector : Page
    {
        public CKFinder.Settings.ConfigFile ConfigFile;

        internal static bool CheckFileName(string fileName)
        {
            if (((fileName == null) || (fileName.Length == 0)) || ((fileName.StartsWith(".") || fileName.EndsWith(".")) || fileName.Contains("..")))
            {
                return false;
            }
            if (Regex.IsMatch(fileName, "[/\\\\:\\*\\?\"\\<\\>\\|\\p{C}]"))
            {
                return false;
            }
            return true;
        }

        protected override void OnLoad(EventArgs e)
        {
            this.ConfigFile.SetCurrent();
            this.ConfigFile.SetConfig();
            CommandHandlerBase base2 = null;
            try
            {
                switch (base.Request.QueryString["command"])
                {
                    case "Init":
                        base2 = new InitCommandHandler();
                        break;

                    case "GetFolders":
                        base2 = new GetFoldersCommandHandler();
                        break;

                    case "GetFiles":
                        base2 = new GetFilesCommandHandler();
                        break;

                    case "Thumbnail":
                        base2 = new ThumbnailCommandHandler();
                        break;

                    case "CreateFolder":
                        base2 = new CreateFolderCommandHandler();
                        break;

                    case "RenameFolder":
                        base2 = new RenameFolderCommandHandler();
                        break;

                    case "DeleteFolder":
                        base2 = new DeleteFolderCommandHandler();
                        break;

                    case "FileUpload":
                        base2 = new FileUploadCommandHandler();
                        break;

                    case "QuickUpload":
                        base2 = new QuickUploadCommandHandler();
                        break;

                    case "DownloadFile":
                        base2 = new DownloadFileCommandHandler();
                        break;

                    case "RenameFile":
                        base2 = new RenameFileCommandHandler();
                        break;

                    case "DeleteFile":
                        base2 = new DeleteFileCommandHandler();
                        break;

                    case null:
                        ConnectorException.Throw(10);
                        break;

                    default:
                        ConnectorException.Throw(10);
                        break;
                }
                if (base2 != null)
                {
                    base2.SendResponse(base.Response);
                }
            }
            catch (ConnectorException exception)
            {
                new ErrorCommandHandler(exception).SendResponse(base.Response);
            }
        }

        public override bool EnableTheming
        {
            get
            {
                return false;
            }
            set
            {
            }
        }

        public override string MasterPageFile
        {
            get
            {
                return null;
            }
            set
            {
            }
        }

        public override string StyleSheetTheme
        {
            get
            {
                return "";
            }
            set
            {
            }
        }

        public override string Theme
        {
            get
            {
                return "";
            }
            set
            {
            }
        }
    }
}

